local skel = fk.CreateSkill({
  name = "efengqi__guhuo",
})

Fk:loadTranslationTable{
  ["efengqi__guhuo"] = "蛊惑",
  [":efengqi__guhuo"] = "当你需要使用或打出你手牌拥有的非装备牌时，你可以扣置一张此牌或装备牌视为之，令其他角色质疑是否为装备牌，首个质疑者翻开之，若为真，其失去一点体力，若为假，此牌作废且其获得之。",

  ["#efengqi__guhuo"] = "蛊惑：你可以转化一张装备牌当其他手牌使用",
  ["#efengqi__guhuo-ask"] = "蛊惑：是否质疑 %dest 声明的 %arg",
  ["#efengqi__guhuo_use"] = "%from 发动了 “%arg2”，声明此牌为 %arg，指定的目标为 %to",
  ["#efengqi__guhuo_no_target"] = "%from 发动了“%arg2”，声明此牌为 %arg",

  ["$efengqi__guhuo1"] = "你信吗？",
  ["$efengqi__guhuo2"] = "猜猜看呐~",
}

skel:addEffect("viewas", {
  pattern = ".|.|.|.|.|basic,trick",
  prompt = "#efengqi__guhuo",
  interaction = function(self, player)
    local all_names = {}
    for _, id in ipairs(player:getCardIds("h")) do
      if Fk:getCardById(id).type ~= Card.TypeEquip then
        table.insertIfNeed(all_names, Fk:getCardById(id).name)
      end
    end
    local names = player:getViewAsCardNames(skel.name, all_names)
    if #names == 0 then return end
    return UI.CardNameBox { choices = names, all_choices = all_names }
  end,
  card_filter = function(self, player, to_select, selected)
    return #selected == 0 and table.contains(player:getCardIds("h"), to_select)
    and Fk.all_card_types[self.interaction.data] ~= nil
    and (self.interaction.data == Fk:getCardById(to_select).name or Fk:getCardById(to_select).type == Card.TypeEquip)
  end,
  view_as = function(self, player, cards)
    if #cards ~= 1 or Fk.all_card_types[self.interaction.data] == nil then return end
    local card = Fk:cloneCard(self.interaction.data)
    card:addFakeSubcards(cards)
    card.skillName = skel.name
    return card
  end,
  before_use = function(self, player, use)
    local room = player.room
    local cards = use.card.fake_subcards
    local card_id = cards[1]
    room:moveCardTo(cards, Card.Processing, nil, fk.ReasonPut, skel.name, nil, false)

    local targets = use.tos
    if targets and #targets > 0 then
      room:sendLog{
        type = "#efengqi__guhuo_use",
        from = player.id,
        to = table.map(targets, Util.IdMapper),
        arg = use.card.name,
        arg2 = skel.name
      }
      room:doIndicate(player.id, targets)
    else
      room:sendLog{
        type = "#efengqi__guhuo_no_target",
        from = player.id,
        arg = use.card.name,
        arg2 = skel.name
      }
    end

    local canuse = true
    local winner
    local players = room:getOtherPlayers(player)
    if #players > 0 then
      local req_data = {
        skel.name, "#efengqi__guhuo-ask::"..player.id..":"..use.card.name,
      }
      local req = Request:new(players, "AskForSkillInvoke")
      req.focus_players = players
      req.focus_text = skel.name
      req.receive_decode = false
      for _, p in ipairs(players) do req:setData(p, req_data) end
      req:ask()
      winner = req.winners[1]
      if winner then
        room:showCards(use.card)
        room:doIndicate(player, {winner})
        if Fk:getCardById(card_id).type == Card.TypeEquip then
          canuse = false
        else
          room:loseHp(winner, 1, skel.name)
        end
      end
    end
    if canuse then
      use.card:addSubcard(card_id)
    else
      room:moveCardTo(card_id, Card.PlayerHand, winner, fk.ReasonJustMove, skel.name)
      --room:moveCardTo(card_id, Card.DiscardPile, nil, fk.ReasonPutIntoDiscardPile, skel.name)
      return "" --skel.name
    end
  end,
  enabled_at_play = function(self, player)
    return not player:isKongcheng()
  end,
  enabled_at_response = function(self, player, response)
    return table.find(player:getCardIds("h"), function (id)
      return Exppattern:Parse(Fk.currentResponsePattern):match(Fk:getCardById(id))
      and Fk:getCardById(id).type ~= Card.TypeEquip
    end) ~= nil
  end,
})

return skel
